from product_upload.util.basic.mysql_util import db_get_one


class BasicGg:
    # 字段顺序与数据库字段一致
    fields = ['id', 'status', 'product_id', 'sku', 'origin_info', 'price_info', 'create_time', 'update_time', 'remark', 'update_by']

    def __init__(self, **kwargs):
        self.id = kwargs.get('id', None)
        self.status = kwargs.get('status', None)
        self.product_id = kwargs.get('product_id', None)
        self.sku = kwargs.get('sku', None)
        self.origin_info = kwargs.get('origin_info', None)
        self.price_info = kwargs.get('price_info', None)
        self.create_time = kwargs.get('create_time', None)
        self.update_time = kwargs.get('update_time', None)
        self.create_time = kwargs.get('remark', None)
        self.update_time = kwargs.get('update_by', None)

    @classmethod
    def from_db(cls, field_names, row) -> 'BasicGg':
        if len(field_names) != len(row):
            raise ValueError("bug!---db field len != query field len")
        data_dict = dict(zip(field_names, row))
        return cls(**data_dict)

    def __repr__(self):
        field_info = []
        for field in self.fields:
            value = getattr(self, field)
            field_info.append(f"{field}={repr(value)}")
        return f"BasicGg=[{', '.join(field_info)}]"


if __name__ == '__main__':
    print(db_get_one("basic_gg", "id=3", BasicGg))
    pass
